<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商业伙伴ID" prop="bpId">
        <el-input
          v-model="queryParams.bpId"
          placeholder="请输入商业伙伴ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="帐号" prop="bankAccountNum">
        <el-input
          v-model="queryParams.bankAccountNum"
          placeholder="请输入帐号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户代码" prop="bankAccountCode">
        <el-input
          v-model="queryParams.bankAccountCode"
          placeholder="请输入账户代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户名" prop="bankAccountName">
        <el-input
          v-model="queryParams.bankAccountName"
          placeholder="请输入账户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="币种" prop="currency">
        <el-input
          v-model="queryParams.currency"
          placeholder="请输入币种"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="启用标志" prop="enabledFlag">
        <el-select v-model="queryParams.enabledFlag" placeholder="请选择启用标志" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="银行全程" prop="bankFullName">
        <el-input
          v-model="queryParams.bankFullName"
          placeholder="请输入银行全程"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支行名称" prop="bankBranchName">
        <el-input
          v-model="queryParams.bankBranchName"
          placeholder="请输入支行名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分/支行ID" prop="bankBranchId">
        <el-input
          v-model="queryParams.bankBranchId"
          placeholder="请输入分/支行ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家" prop="countryId">
        <el-input
          v-model="queryParams.countryId"
          placeholder="请输入国家"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省" prop="provinceId">
        <el-input
          v-model="queryParams.provinceId"
          placeholder="请输入省"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="cityId">
        <el-input
          v-model="queryParams.cityId"
          placeholder="请输入市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区县" prop="districtId">
        <el-input
          v-model="queryParams.districtId"
          placeholder="请输入区县"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="贷款账户" prop="loanAccount">
        <el-input
          v-model="queryParams.loanAccount"
          placeholder="请输入贷款账户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回款账户" prop="paymentAccount">
        <el-input
          v-model="queryParams.paymentAccount"
          placeholder="请输入回款账户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结算账户" prop="balanceAccount">
        <el-input
          v-model="queryParams.balanceAccount"
          placeholder="请输入结算账户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户用途" prop="bankAccountApplication">
        <el-input
          v-model="queryParams.bankAccountApplication"
          placeholder="请输入账户用途"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="tssBankCode">
        <el-input
          v-model="queryParams.tssBankCode"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="tssBankNum">
        <el-input
          v-model="queryParams.tssBankNum"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户性质" prop="accountNature">
        <el-input
          v-model="queryParams.accountNature"
          placeholder="请输入账户性质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="大额行号" prop="cnapsCode">
        <el-input
          v-model="queryParams.cnapsCode"
          placeholder="请输入大额行号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="swiftCode">
        <el-input
          v-model="queryParams.swiftCode"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户日期" prop="accountStartDate">
        <el-date-picker clearable
          v-model="queryParams.accountStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开户日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="销户日期" prop="accountEndDate">
        <el-date-picker clearable
          v-model="queryParams.accountEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择销户日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['lease:bpMasterBankAccount:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['lease:bpMasterBankAccount:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['lease:bpMasterBankAccount:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['lease:bpMasterBankAccount:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bpMasterBankAccountList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="银行账户ID / PK" align="center" prop="bankAccountId" />
      <el-table-column label="商业伙伴ID" align="center" prop="bpId" />
      <el-table-column label="帐号" align="center" prop="bankAccountNum" />
      <el-table-column label="账户代码" align="center" prop="bankAccountCode" />
      <el-table-column label="账户名" align="center" prop="bankAccountName" />
      <el-table-column label="币种" align="center" prop="currency" />
      <el-table-column label="启用标志" align="center" prop="enabledFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enabledFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="银行全程" align="center" prop="bankFullName" />
      <el-table-column label="支行名称" align="center" prop="bankBranchName" />
      <el-table-column label="分/支行ID" align="center" prop="bankBranchId" />
      <el-table-column label="国家" align="center" prop="countryId" />
      <el-table-column label="省" align="center" prop="provinceId" />
      <el-table-column label="市" align="center" prop="cityId" />
      <el-table-column label="区县" align="center" prop="districtId" />
      <el-table-column label="贷款账户" align="center" prop="loanAccount" />
      <el-table-column label="回款账户" align="center" prop="paymentAccount" />
      <el-table-column label="结算账户" align="center" prop="balanceAccount" />
      <el-table-column label="账户用途" align="center" prop="bankAccountApplication" />
      <el-table-column label="${comment}" align="center" prop="tssBankCode" />
      <el-table-column label="${comment}" align="center" prop="tssBankNum" />
      <el-table-column label="账户性质" align="center" prop="accountNature" />
      <el-table-column label="大额行号" align="center" prop="cnapsCode" />
      <el-table-column label="${comment}" align="center" prop="swiftCode" />
      <el-table-column label="开户日期" align="center" prop="accountStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accountStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="销户日期" align="center" prop="accountEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accountEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['lease:bpMasterBankAccount:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['lease:bpMasterBankAccount:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商业伙伴银行账户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商业伙伴ID" prop="bpId">
          <el-input v-model="form.bpId" placeholder="请输入商业伙伴ID" />
        </el-form-item>
        <el-form-item label="帐号" prop="bankAccountNum">
          <el-input v-model="form.bankAccountNum" placeholder="请输入帐号" />
        </el-form-item>
        <el-form-item label="账户代码" prop="bankAccountCode">
          <el-input v-model="form.bankAccountCode" placeholder="请输入账户代码" />
        </el-form-item>
        <el-form-item label="账户名" prop="bankAccountName">
          <el-input v-model="form.bankAccountName" placeholder="请输入账户名" />
        </el-form-item>
        <el-form-item label="币种" prop="currency">
          <el-input v-model="form.currency" placeholder="请输入币种" />
        </el-form-item>
        <el-form-item label="启用标志" prop="enabledFlag">
          <el-select v-model="form.enabledFlag" placeholder="请选择启用标志">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="银行全程" prop="bankFullName">
          <el-input v-model="form.bankFullName" placeholder="请输入银行全程" />
        </el-form-item>
        <el-form-item label="支行名称" prop="bankBranchName">
          <el-input v-model="form.bankBranchName" placeholder="请输入支行名称" />
        </el-form-item>
        <el-form-item label="分/支行ID" prop="bankBranchId">
          <el-input v-model="form.bankBranchId" placeholder="请输入分/支行ID" />
        </el-form-item>
        <el-form-item label="国家" prop="countryId">
          <el-input v-model="form.countryId" placeholder="请输入国家" />
        </el-form-item>
        <el-form-item label="省" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入省" />
        </el-form-item>
        <el-form-item label="市" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区县" prop="districtId">
          <el-input v-model="form.districtId" placeholder="请输入区县" />
        </el-form-item>
        <el-form-item label="贷款账户" prop="loanAccount">
          <el-input v-model="form.loanAccount" placeholder="请输入贷款账户" />
        </el-form-item>
        <el-form-item label="回款账户" prop="paymentAccount">
          <el-input v-model="form.paymentAccount" placeholder="请输入回款账户" />
        </el-form-item>
        <el-form-item label="结算账户" prop="balanceAccount">
          <el-input v-model="form.balanceAccount" placeholder="请输入结算账户" />
        </el-form-item>
        <el-form-item label="账户用途" prop="bankAccountApplication">
          <el-input v-model="form.bankAccountApplication" placeholder="请输入账户用途" />
        </el-form-item>
        <el-form-item label="${comment}" prop="tssBankCode">
          <el-input v-model="form.tssBankCode" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="tssBankNum">
          <el-input v-model="form.tssBankNum" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="账户性质" prop="accountNature">
          <el-input v-model="form.accountNature" placeholder="请输入账户性质" />
        </el-form-item>
        <el-form-item label="大额行号" prop="cnapsCode">
          <el-input v-model="form.cnapsCode" placeholder="请输入大额行号" />
        </el-form-item>
        <el-form-item label="${comment}" prop="swiftCode">
          <el-input v-model="form.swiftCode" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="开户日期" prop="accountStartDate">
          <el-date-picker clearable
            v-model="form.accountStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开户日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="销户日期" prop="accountEndDate">
          <el-date-picker clearable
            v-model="form.accountEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择销户日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBpMasterBankAccount, getBpMasterBankAccount, delBpMasterBankAccount, addBpMasterBankAccount, updateBpMasterBankAccount } from "@/api/lease/bpMasterBankAccount";

export default {
  name: "BpMasterBankAccount",
  dicts: ['sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商业伙伴银行账户信息表格数据
      bpMasterBankAccountList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bpId: null,
        bankAccountNum: null,
        bankAccountCode: null,
        bankAccountName: null,
        currency: null,
        enabledFlag: null,
        bankFullName: null,
        bankBranchName: null,
        bankBranchId: null,
        countryId: null,
        provinceId: null,
        cityId: null,
        districtId: null,
        loanAccount: null,
        paymentAccount: null,
        balanceAccount: null,
        bankAccountApplication: null,
        tssBankCode: null,
        tssBankNum: null,
        accountNature: null,
        cnapsCode: null,
        swiftCode: null,
        accountStartDate: null,
        accountEndDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bpId: [
          { required: true, message: "商业伙伴ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商业伙伴银行账户信息列表 */
    getList() {
      this.loading = true;
      listBpMasterBankAccount(this.queryParams).then(response => {
        this.bpMasterBankAccountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bankAccountId: null,
        bpId: null,
        bankAccountNum: null,
        bankAccountCode: null,
        bankAccountName: null,
        currency: null,
        enabledFlag: null,
        bankFullName: null,
        bankBranchName: null,
        bankBranchId: null,
        countryId: null,
        provinceId: null,
        cityId: null,
        districtId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        refV01: null,
        refV02: null,
        refV03: null,
        refV04: null,
        refV05: null,
        refN01: null,
        refN02: null,
        refN03: null,
        refN04: null,
        refN05: null,
        refD01: null,
        refD02: null,
        refD03: null,
        refD04: null,
        refD05: null,
        loanAccount: null,
        paymentAccount: null,
        balanceAccount: null,
        bankAccountApplication: null,
        tssBankCode: null,
        tssBankNum: null,
        accountNature: null,
        cnapsCode: null,
        swiftCode: null,
        accountStartDate: null,
        accountEndDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.bankAccountId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商业伙伴银行账户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const bankAccountId = row.bankAccountId || this.ids
      getBpMasterBankAccount(bankAccountId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商业伙伴银行账户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.bankAccountId != null) {
            updateBpMasterBankAccount(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBpMasterBankAccount(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const bankAccountIds = row.bankAccountId || this.ids;
      this.$modal.confirm('是否确认删除商业伙伴银行账户信息编号为"' + bankAccountIds + '"的数据项？').then(function() {
        return delBpMasterBankAccount(bankAccountIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lease/bpMasterBankAccount/export', {
        ...this.queryParams
      }, `bpMasterBankAccount_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
